<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>宣传文案</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="/static/hAdmin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/static/hAdmin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="/static/hAdmin/css/plugins/toastr/toastr.min.css" rel="stylesheet">
    <link href="/static/hAdmin/css/animate.css" rel="stylesheet">
    <!--<link href="/static/hAdmin/css/style.css?v=4.1.0" rel="stylesheet">-->
    <link href="/static/hAdmin/css/style3.css?v=4.0" rel="stylesheet">
    <!-- Sweet Alert -->
    <link href="/static/hAdmin/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <style>
    .addList {
        padding: 10px 30px 10px 30px;
        height: 90px;
        margin-top: 3px
    }
    .marTop20{
        margin-top: 20px;
    }
</style>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <span id="gloUrl" style="display: none"></span>
        <div class="row">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>系统宣传文案</h5>
                    <div class="ibox-tools">

                        <a class="dropdown-toggle userUnDo" href="javascript:void(0)" data-toggle="modal" data-target="#myModal">
                            <i class="fa fa-plus"></i>
                        </a>


                    </div>
                </div>
                <div class="ibox-content">

<!--                        <div class="panel-group" id="accordion">-->
                            <div class="faq-item" id="accordion">

                            </div>

<!--                        </div>-->

                </div>
                <!--                        页码控制-->
                <div ajaxUrl="www.baidu.com" currentPage="1" id="pageHelper">
                    <div class="pageBottom col-xs-10 col-xs-offset-1" style="margin-top: 20px">
                        <nav aria-label="...">
                            <ul class="pager">
                                <li class="previous disabled"><a href="javascript:void(0)"><span aria-hidden="true">&larr;</span>
                                    上一页</a></li>
                                <li>
                                    <span>共</span>
                                    <span id="data_total">${total}</span>
                                    <span>条数据</span>
                                </li>
                                <li class="next"><a href="javascript:void(0)">下一页 <span
                                        aria-hidden="true">&rarr;</span></a></li>
                            </ul>
                        </nav>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <!--弹出框-->
    <div class="modal inmodal" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated bounceInRight" style="min-height: 400px;overflow-y: scroll">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">&times;</span>
                        <span class="sr-only">关闭</span>
                    </button>
                    <i class="fa fa-users modal-icon" style="font-size: 60px"></i>
                    <h4 class="modal-title">新增宣传文案</h4>

                </div>

                <div class="formListAdd">
                    <div class="modal-body addList">

                        <div class="form-group col-xs-12">
                            <label>视频文件</label>
                            <input type="file" id="insFile" required="required" multiple="multiple" name="file"
                                   class="form-control"></div>
                    </div>
                    <div class="modal-body addList">
                        <div class="form-group col-xs-12">
                            <label>宣传文案名称</label>
                            <input type="text" id="caseName" placeholder="输入宣传文案名称" class="form-control"></div>
                    </div>

                    <div class="modal-body addList">
                        <div class="form-group col-xs-12">
                            <label>所属景点/特色</label>
                            <select id="courseId" class="form-control">

                            </select>
                        </div>
                    </div>

                    <div class="modal-body addList" style="height: 190px;">
                        <div class="form-group col-xs-12">
                            <label for="caseDes">宣传文案描述</label>
                         <textarea id="caseDes" rows="5" class="form-control"></textarea>
                    </div>
                    </div>



                    <div class="modal-footer">
                        <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-success" data-dismiss="modal" id="confirmAddEq">确定</button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!--弹出框-->
    <div class="modal inmodal" id="myModalEd" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated bounceInRight" style="min-height: 400px;overflow-y: scroll">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">&times;</span>
                        <span class="sr-only">关闭</span>
                    </button>
                    <i class="fa fa-users modal-icon" style="font-size: 60px"></i>
                    <h4 class="modal-title">修改宣传文案</h4>

                </div>

                <div class="formListAdd">
                    <div class="modal-body addList">

                        <div class="form-group col-xs-12">
                            <label>视频文件</label>
                            <input type="file" id="editFile" required="required" multiple="multiple" name="file"
                                   class="form-control"></div>
                    </div>
                    <div class="modal-body addList">
                        <div class="form-group col-xs-12">
                            <label>宣传文案名称</label>
                            <input type="text" id="editcaseName" placeholder="输入宣传文案名称" class="form-control"></div>
                    </div>

                    <div class="modal-body addList">
                        <div class="form-group col-xs-12">
                            <label>所属景点/特色</label>
                            <select id="editcourseId" class="form-control">

                            </select>
                        </div>
                    </div>

                    <div class="modal-body addList" style="height: 190px;">
                        <div class="form-group col-xs-12">
                            <label for="caseDes">宣传文案描述</label>
                            <textarea id="editcaseDes" rows="5" class="form-control"></textarea>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-success" data-dismiss="modal" id="confirmEditEq">确定</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- 全局js -->
    <script src="/static/hAdmin/js/jquery.min.js?v=2.1.4"></script>
    <script src="/static/hAdmin/js/bootstrap.min.js?v=3.3.6"></script>
    <!-- Sweet alert -->
    <script src="/static/hAdmin/js/plugins/sweetalert/sweetalert.min.js"></script>

    <!-- 自定义js -->
    <script src="/static/hAdmin/js/content.js?v=1.0.0"></script>
    <!--    分页js -->
    <!--<script src="/static/wmmJs/public/PageHelper.js"></script>-->
    <script src="/static/hAdmin/js/plugins/toastr/toastr.min.js"></script>
    <script src="/static/js/GloJs.js"></script>
    <script>


        $(function () {

            let Glo_BaseUrl = $("#gloUrl").attr("gloUValue")
            let Glo_user = localStorage.getItem("userId")
            let currentPage = $("#pageHelper").attr("currentPage");
            //获取景点/特色列表
            function getSchedulingTempList(){

                $.ajax({
                    url: Glo_BaseUrl + "/courseInfo/list",
                    type: "get",
                    data:{
                        "pageSize": 999,
                        "pageNum": 1,

                    },
                    success: function (data) {
                        $("#courseId").html("").append(`<option value="">请选择景点/特色</option>`)
                        for (let i = 0; i < data.list.length; i++) {
                            let item = data.list[i]
                            $("#courseId").append(` <option value="${item.id}">${item.courseName}</option>`)
                            $("#editcourseId").append(` <option value="${item.id}">${item.courseName}</option>`)
                        }


                    },
                    error: function () {
                        alert("服务器异常！network error！")
                    }
                })
            }
            getSchedulingTempList()


            function getTitleList(num) {
                let total = 0;//总数
                let pageSize = 6;//每页条数
                let html_dom = $("#accordion")


                let searchKey = $("#searchKey").val()
                if (num === 1) {
                    searchKey = ""
                    $("#searchKey").val("")
                }
                setTimeout(function () {
                    $.ajax({
                        url: Glo_BaseUrl + "/caseInfo/list",
                        type: "get",
                        data: {
                            "pageSize": pageSize,
                            "pageNum": currentPage,
                            "searchKey": searchKey,
                            "status": $("#status").val(),

                        },
                        success: function (data) {

                            let ListStr = ''
                            total = data.total
                            console.log(data)
                            for (let i = 0; i < data.list.length; i++) {
                               ListStr +=`  <div class="marTop20">
                                    <div class="row">
                                        <div class="col-md-7">
                                            <a data-toggle="collapse" href="faq.html#faq${data.list[i].id}" class="faq-question">${data.list[i].caseName}</a>
                                            <small><strong>发布时间</strong> <i class="fa fa-clock-o"></i>${data.list[i].createTime}</small>
                                        </div>
                                        <div class="col-md-3">
                                            <span class="small font-bold">宣传文案所属景点/特色</span>
                                            <div class="tag-list">
                                                <span class="tag-item">${data.list[i].courseName}</span>

                                            </div>
                                        </div>
                                        <div class="col-md-2 text-right">
                                            <span class="small font-bold">
                                             <button class="btn btn-warning btn-sm editThis userUnDo"
                                             id="toEdit_${data.list[i].id}" title="编辑"
                                              data-toggle="modal" data-target="#myModalEd"><i class="fa fa-pencil"></i></button>
                                            <button class="btn btn-danger btn-sm toDelete userUnDo" id="toDelete_${data.list[i].id}" title="删除"><i class="fa fa-trash"></i></button>

                                           </span>

                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-sm-12">
                                            <div id="faq${data.list[i].id}" class="panel-collapse faq-answer collapse" aria-expanded="false" style="height: 32px;">
                                                <span style="font-size: 18px">
                                                   ${data.list[i].caseDes}
                                                </span>
                                            </div>
                                        </div>
                                    </div>
                                </div>`

                            }

                            if (data.code !== 500) {
                                html_dom.html("")
                                html_dom.append(ListStr)
                            } else {
                                alert("获取失败")
                            }
                            total = data.total
                            $.ajax({
                                url: Glo_BaseUrl + "/system/user/detail",
                                type: "get",
                                data: {
                                    "id":Glo_user
                                },
                                success: function (data) {
                                    console.log(data)
                                    let role = data.Data.role
                                    if (role === "1"){//用户
                                        $(".adminFun ").css({display:"none"})
                                        $(".manFun ").css({display:"none"})
                                        $(".userUnDo ").css({display:"none"})
                                    }else if (role === "2"){//管理员
                                        $(".manFun ").css({display:"none"})
                                        $(".userFun ").css({display:"none"})
                                        $(".adminUnDo ").css({display:"none"})
                                    }else {
                                        $(".adminFun ").css({display:"none"})
                                        $(".userFun ").css({display:"none"})
                                    }
                                },
                                error: function () {
                                    alert("服务器异常！network error！")
                                }
                            })
                            $("#data_total").html(data.total);
                            //下一页
                            $('.next').unbind().click(function () {
                                if (currentPage * pageSize >= total) {
                                    toastr.error("已经是最后一页了！", '提醒')
                                } else {
                                    currentPage++;
                                    $("#pageHelper").attr("currentPage", currentPage);
                                    if (currentPage > 0) {
                                        $(".previous").removeClass("disabled")
                                    }
                                    $(".project-list").addClass("animated bounceOutLeft")
                                    setTimeout(function () {
                                        $(".project-list").removeClass("animated bounceOutLeft").addClass("animated bounceInRight")
                                    }, 500)
                                    getTitleList(2)
                                }

                            });
                            //上一页
                            $('.previous').unbind().click(function () {
                                currentPage--;
                                $("#pageHelper").attr("currentPage", currentPage);
                                if (currentPage === 0) {
                                    currentPage = 1;
                                    $("#pageHelper").attr("currentPage", currentPage);
                                    $(".previous").addClass("disabled");
                                } else {
                                    $(".project-list").addClass("animated bounceOutRight")
                                    setTimeout(function () {
                                        $(".project-list").removeClass("animated bounceOutRight bounceInRight").addClass("animated bounceInLeft")
                                    }, 500)
                                    getTitleList(2)
                                }
                            });

                            //删除病例信息
                            $(".toDelete").unbind().click(function () {
                                localStorage.setItem("id", $(this).attr("id").split("toDelete_")[1]);
                                let id = localStorage.getItem("id")
                                swal({
                                    title: "您确定要删除该宣传文案吗",
                                    text: "删除后将不可恢复！",
                                    type: "warning",
                                    showCancelButton: true,
                                    confirmButtonColor: "#DD6B55",
                                    confirmButtonText: "删除",
                                    cancelButtonText: "取消",
                                    closeOnConfirm: false
                                }, function () {
                                    $.ajax({
                                        url: Glo_BaseUrl + "/caseInfo/del",
                                        type: "post",
                                        data: {
                                            id: id,

                                        },
                                        success: function (data) {

                                            swal("删除成功", "该宣传文案已经删除", "success");
                                            getTitleList(2)
                                        },
                                        error: function () {
                                            alert("服务器异常！network error！")
                                        }
                                    })

                                });

                            });
                            //根据权限 隐藏删除按钮
                            $.ajax({
                                url: Glo_BaseUrl + "/system/user/detail",
                                type: "get",
                                data: {
                                    "id":Glo_user
                                },
                                success: function (data) {
                                    console.log(data)
                                    let role = data.Data.role
                                    if (role === "1"){//用户
                                        $(".adminFun ").css({display:"none"})
                                        $(".docFun ").css({display:"none"})
                                    }else if (role === "2"){//管理员
                                        $(".docFun ").css({display:"none"})
                                        $(".userFun ").css({display:"none"})
                                    }else {
                                        $(".adminFun ").css({display:"none"})
                                    }
                                },
                                error: function () {
                                    alert("服务器异常！network error！")
                                }
                            })
                            //将编辑框内容填写
        $(".editThis").click(function (){
            localStorage.setItem("id", $(this).attr("id").split("toEdit_")[1]);
            let id = localStorage.getItem("id")
            $.ajax({
                url: Glo_BaseUrl + "/caseInfo/detail",
                type: "get",
                data: {
                    "id":id
                },
                success: function (data) {
                    console.log(data)
$("#editcaseName").val(data.Data.caseName)
$("#editcaseDes").val(data.Data.caseDes)
$("#editcourseId").val(data.Data.courseId)
                },
                error: function () {
                    alert("服务器异常！network error！")
                }
            })
        })
                            //确认编辑
                            $("#confirmEditEq").click(function (){
                                let id = localStorage.getItem("id")
                                var formData = new FormData();//这里需要实例化一个FormData来进行文件上传
                                // formData.append("file",$("#editFile")[0].files[0]);
                                formData.append("caseName",$("#editcaseName").val());
                                if ($("#editFile")[0].files[0] != undefined){
                                    formData.append("file",$("#editFile")[0].files[0]);
                                }
                                formData.append("caseDes",$("#editcaseDes").val());
                                formData.append("courseId",$("#editcourseId").val());
                                formData.append("id",id);

                                $.ajax({
                                    url: Glo_BaseUrl + "/caseInfo/edit",
                                    type: "post",
                                    data:formData,
                                    processData : false,
                                    contentType : false,
                                    success: function (data) {
                                        console.log(data)
                                        if (data.code == 200){
                                            swal("更新成功", "该宣传文案已经更新成功", "success");
                                        }else {
                                            swal("更新失败", "该宣传文案更新失败", "error");
                                        }
                                     getTitleList(2)
                                    },
                                    error: function () {
                                        alert("服务器异常！network error！")
                                    }
                                })
                            })
                        },
                        error: function () {
                            alert("服务器异常！network error！")
                        }
                    });
                }, 300)


            }


            //*******************************************
            getTitleList(2)
            $("#getByKeywords").click(function () {
                getTitleList(2)
            })
            $(".loading-example-btn").click(function () {
                getTitleList(1)
            })

            // beginPage()
            function simpleLoad(btn, state) {
                if (state) {
                    btn.children().addClass('fa-spin');
                    btn.contents().last().replaceWith(" Loading");
                } else {
                    setTimeout(function () {
                        btn.children().removeClass('fa-spin');
                        btn.contents().last().replaceWith(" Refresh");
                    }, 2000);
                }
            }

            $(document).ready(function () {
                $('#loading-example-btn').click(function () {
                    btn = $(this);
                    simpleLoad(btn, true)
                    simpleLoad(btn, false)
                    getTitleList(1)
                });
            });


            //-----------------------------
            //添加宣传文案
            $("#confirmAddEq").click(function () {
                var formData = new FormData();//这里需要实例化一个FormData来进行文件上传
                // formData.append("file",$("#editFile")[0].files[0]);
                formData.append("caseName",$("#caseName").val());
                if ($("#insFile")[0].files[0] != undefined){
                    formData.append("file",$("#insFile")[0].files[0]);
                }
                formData.append("caseDes",$("#caseDes").val());
                formData.append("courseId",$("#courseId").val());


                $.ajax({
                    url: Glo_BaseUrl + "/caseInfo/add",
                    type: "post",
                    data:formData,
                    processData : false,
                    contentType : false,
                    success: function (data) {
                        toastr.success(data.msg, '提示')

                        getTitleList(1)
                    },
                    error: function () {
                        alert("服务器异常！network error！")
                    }
                })
            })
        })
    </script>

</body>

</html>
